9 typedef unsigned long long int lluint
;
10 typedef vector
<int> vint
;
11 typedef vector
<vint
> vvint
;
13 #define forsn(i, s, n) for (int i = (s); i < (n); i++)
14 #define forn(i, n) forsn (i, 0, n)
16 void pkmp(const string
& s
, vint
& f
) {
18 forsn (i
, 1, s
.size() + 1) {
19 while (z
!= -1 && s
[i
- 1] != s
[z
]) z
= f
[z
];
20 f
[i
] = ++z
; // z might be -1
26 #define ALPHA_SIZE 128
27 void build_transitions(const string
& s
) {
28 uint n
= s
.size() + 1;
30 tran
= vvint(n
, vint(ALPHA_SIZE
, 0));
33 forn (a
, ALPHA_SIZE
) {
35 while (z
!= -1 && s
[z
] != (char)a
) z
= f
[z
];
36 tran
[state
][a
] = z
+ 1;
48 #define buf_sync() { \
49 cin.getline(buf, TAMBUF + 1); \
51 buf_size = cin.gcount(); \
55 #define buf_start() { \
62 const int final
= tran
.size() - 1;
67 cout
<< (pos
+ i
- final
) << " ";
69 state
= tran
[state
][buf
[i
]];
71 if (buf_size
< TAMBUF
) break;
83 assert(needle_size
== needle
.size());
86 build_transitions(needle
);